﻿/**
作者：景伟
时间：2009-11-21
功能：实现角色管理
**/
var ArrList = new Array();
var PageSize = 10;
function ShowMain() {
    GetRoleList(1);
}

//获取"信息列表"
function GetRoleList(page) {
    var url = encodeURI(SBasePath + '/action/RolesManage/RoleList.aspx');
    var pars = encodeURI("?PageIndex=" + page + "&PageSize=" + PageSize);
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetRoleList, onFailure: fGetRoleList });

}
//获取"信息列表"成功
function sGetRoleList(o) {
    ArrList = MapAdmin_Roles(o);
    Total = MapPage(o, "RecordCount");
    PageIndex = MapPage(o, "PageIndex");
    PageTotal = Math.ceil(Total / PageSize)
    ShowContent();

}
function fGetRoleList() { }

//确认删除
function Del(RoleID) {
    if (RoleID == "ChkAllValue") {
        var idstr = SelectIDs(RoleID);
        if (idstr.length == 0) {
            MsgDlg(GetMsg("10"));
        }
        else {
            ConfrimDlg(GetMsg("2"), "DelRoles('" + idstr + "')");
        }
    } else {
        ConfrimDlg(GetMsg("2"), "DelRoles('" + RoleID + "')");
    }
}
var DelRoles = function(RolesID)//删除
{

    var url = encodeURI(SBasePath + '/action/RolesManage/RoleDel.aspx');
    var pars = encodeURI('?idstr=' + RolesID);
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sDelRoles, onFailure: fDelRoles });

};

//操作成功
function sDelRoles(o) {
    var root = o.responseXML.documentElement;
    var flag = GetXmlData(root, "Value");
    if (flag == "true") {
        MsgDlgLocal("删除成功！");
    }
    else {
        MsgDlg(GetMsg("0"));
    }
}

//操作失败
function fDelRoles(o) {
}

//增加用户
function RolesAdd() {
    location.href = SBasePath + "/htm/RolesManage/AddRole.htm";
}
//全选
function SelectAll(id, name) {
    var checks = document.getElementsByTagName("input");
    for (var i = 0; i < checks.length; i++) {
        if (checks[i].name == name) {

            checks[i].checked = document.getElementById(id).checked;
        }
    }
};

function SelectIDs(name) {
    var checks = document.getElementsByTagName("input");
    var str = "";
    for (var i = 0; i < checks.length; i++) {
        if (checks[i].name == name && checks[i].checked) {
            str += checks[i].value + ",";
        }
    }
    return str;
};

function Edit(id) {
    window.top.frames["Content"].location.href = SBasePath + "/htm/RolesManage/EditRole.htm?RoleID=" + id;
}

function openwin1(url) {
    window.open(url, null, "scrollbars=yes, resizable=no, toolbar=no, menubar=no, location=no, directories=no,width=200,height=768,top=0,left=300");
}

function ShowContent() {
    var str = "";

    str += '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">'
    str += '        <tr>';
    str += '            <td height="30">';
    str += '                <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '                    <tr>';
    str += '                        <td width="15" height="30" background="../../img/tab_03.gif">';
    str += '                          </td>';
    str += '                        <td  background="../../img/tab_05.gif">';
    str += '                            <img src="../../img/311.gif" width="16" height="16" />';
    str += '                            <span class="title1">角色列表</span>';
    str += '                        </td>';
    str += '                        <td  background="../../img/tab_05.gif">';
    str += '                            <table border="0" align="right" cellpadding="0" cellspacing="0">';
    str += '                                <tr>';
    str += '                                    <td width="60">';
    str += '                                        <table width="87%" border="0" cellpadding="0" cellspacing="0">';
    str += '                                            <tr>';
    str += '                                                <td>';
    str += '                                                    <div align="center">';
    str += '                                                        <input id="ChkAll" type="checkbox" onclick=\'SelectAll("ChkAll","ChkAllValue")\' />';
    str += '                                                    </div>';
    str += '                                                </td>';
    str += '                                                <td>';
    str += '                                                    <div align="center" class="f_green">全选</div>';
    str += '                                                </td>';
    str += '                                            </tr>';
    str += '                                        </table>';
    str += '                                    </td>';
    str += '                                    <td width="60">';
    str += '                                        <table width="90%" border="0" cellpadding="0" cellspacing="0">';
    str += '                                            <tr>';
    str += '                                                <td>';
    str += '                                                    <div align="center">';
    str += '                                                        <img src="../../img/001.gif" width="14" height="14" /></div>';
    str += '                                                </td>';
    str += '                                                <td>';
    str += '                                                    <div align="center" class="f_green"><a href="javascript:RolesAdd()">新增</a></div>';
    str += '                                                </td>';
    str += '                                            </tr>';
    str += '                                        </table>';
    str += '                                    </td>';

    str += '                                    <td width="52">';
    str += '                                        <table width="88%" border="0" cellpadding="0" cellspacing="0">';
    str += '                                            <tr>';
    str += '                                                <td>';
    str += '                                                    <div align="center">';
    str += '                                                        <img src="../../img/083.gif" width="14" height="14" /></div>';
    str += '                                                </td>';
    str += '                                                <td>';
    str += '                                                    <div align="center" class="f_green"> <a href="javascript:Del(\'ChkAllValue\')">删除</a></div>';
    str += '                                                </td>';
    str += '                                            </tr>';
    str += '                                        </table>';
    str += '                                    </td>';
    str += '                                </tr>';
    str += '                            </table>';
    str += '                        </td>';
    str += '                        <td width="14" background="../../img/tab_07.gif">';
    str += '                        </td>';
    str += '                    </tr>';
    str += '                </table>';
    str += '            </td>';
    str += '        </tr>';
    str += '        <tr>';
    str += '            <td>';
    str += '                <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '                    <tr>';
    str += '                        <td width="9" background="../../img/tab_12.gif"> &nbsp;</td>';
    str += '                        <td bgcolor="#f3ffe3">';
    str += '                            <table width="99%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98">';
    str += '                                <tr>';
    str += '                                    <td width="6%" height="26" background="../../img/tab_14.gif">';
    str += '                                        <div align="center" class="f_green">选择</div> ';
    str += '                                    </td>';
    str += '                                    <td width="5%" height="18" background="../../img/tab_14.gif">';
    str += '                                        <div align="center" class="f_green">序号</div>';
    str += '                                    </td>';
    str += '                                    <td height="18" width="13%" background="../../img/tab_14.gif">';
    str += '                                        <div align="center" class="f_green">角色名</div>';
    str += '                                    </td>';
    str += '                                    <td width="30%" height="18" background="../../img/tab_14.gif">';
    str += '                                        <div align="center" class="f_green">角色描述</div>';
    str += '                                    </td>';
    str += '                                    <td width="7%" height="18" background="../../img/tab_14.gif">';
    str += '                                        <div align="center" class="f_green">角色权限</div>';
    str += '                                    </td>';
    str += '                                    <td width="7%" height="18" background="../../img/tab_14.gif">';
    str += '                                        <div align="center" class="f_green">编辑</div>';
    str += '                                    </td>';
    str += '                                    <td width="7%" height="18" background="../../img/tab_14.gif">';
    str += '                                        <div align="center" class="f_green">删除</div>';
    str += '                                    </td>';
    str += '                                </tr>';

    for (var i = 0; i < ArrList.length; i++) {
        str += '                                <tr class="bg_w" onmouseout="this.className=\'bg_w\'" onmouseover="this.className=\'bg_g\'">';
        str += '                                    <td height="20">';
        str += '                                        <div align="center">';
        str += '                                            <input name="ChkAllValue" type="checkbox" class="" value="' + ArrList[i].RoleID + '"/>';
        str += '                                        </div>';
        str += '                                    </td>';
        str += '                                    <td height="18" class="content"><div align="center">' + (i + 1) + '</div></td>';
        str += '                                    <td height="18" class="content"><div align="center">' + ArrList[i].RoleName + '</div></td>';
        str += '                                    <td height="18" class="content"><div align="center">' + ArrList[i].RoleDesc + '</div></td>';
        str += '                                    <td height="18" class="content">';
        str += '                                      <div align="center">';
        str += '                                        <span><img src="../../img/a1.gif" width="9" height="9" /></span><span> [</span><a href="#" onclick="openwin1(\'../../action/rolesmanage/left.aspx?roleid=' + ArrList[i].RoleID + '\')">权限</a><span>]</span></div>';
        str += '                                    </td>';
        str += '                                    <td height="18" class="content">';
        str += '                                      <div align="center">';
        str += '                                        <span><img src="../../img/037.gif" width="9" height="9" /></span><span> [</span><a href="javascript:Edit(\'' + ArrList[i].RoleID + '\')">编辑</a><span>]</span></div>';
        str += '                                    </td>';
        str += '                                    <td height="18">';
        str += '                                      <div align="center">';
        str += '                                        <span><img src="../../img/010.gif" width="9" height="9" /></span><span> [</span><a href="javascript:Del(\'' + ArrList[i].RoleID + '\')">删除</a><span>]</span></div>';
        str += '                                    </td>';
        str += '                                </tr>';
    }
    str += '                            </table>';
    str += '                        </td>';
    str += '                        <td width="9" background="../../img/tab_16.gif">&nbsp;</td>';
    str += '                    </tr>';
    str += '                </table>';
    str += '            </td>';
    str += '        </tr>';
    str += '        <tr>';
    str += '            <td height="29">';
    str += '                <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '                    <tr>';
    str += '                        <td width="15" height="29">';
    str += '                            <img src="../../img/tab_20.gif" width="15" height="29" />';
    str += '                        </td>';
    str += '                        <td background="../../img/tab_21.gif">';
    str += '                            <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '                                <tr>';
    str += '                                    <td width="25%" height="29" nowrap="nowrap">';
    str += '                                   <span class="f_green">共' + Total + '条记录, 当前第' + PageIndex + '/' + PageTotal + '页,每页' + PageSize + '条纪录</span>';
    str += '                                    </td>';
    str += '                                    <td width="75%" valign="top">';
    str += '                                        <div align="right">';
    if (PageTotal > 1) {
        str += '                                            <table width="352" height="20" border="0" cellpadding="0" cellspacing="0">';
        str += '                                                <tr>';
        str += '                                                    <td width="62" height="22" valign="middle">';
        str += '                                                        <div align="right">';
        str += '                                                          <a href="javascript:void(0)" onclick="FirstPage(\'GetRoleList\')"><img src="../../img/first.gif" border="0" width="37" height="15" /></a></div>';
        str += '                                                    </td>';
        str += '                                                    <td width="50" height="22" valign="middle">';
        str += '                                                        <div align="right">';
        str += '                                                            <a href="javascript:void(0)" onclick="BackPage(\'GetRoleList\')"><img src="../../img/back.gif" border="0" width="43" height="15" /></a></div>';
        str += '                                                    </td>';
        str += '                                                    <td width="54" height="22" valign="middle">';
        str += '                                                        <div align="right">';
        str += '                                                            <a href="javascript:void(0)" onclick="NextPage(\'GetRoleList\')"><img src="../../img/next.gif" border="0" width="43" height="15" /></a></div>';
        str += '                                                    </td>';
        str += '                                                    <td width="49" height="22" valign="middle">';
        str += '                                                        <div align="right">';
        str += '                                                            <a href="javascript:void(0)" onclick="LastPage(\'GetRoleList\')"><img src="../../img/last.gif" border="0" width="37" height="15" /></a></div>';
        str += '                                                    </td>';
        str += '                                                    <td width="59" height="22" valign="middle">';
        str += '                                                        <div align="right">';
        str += '                                                            转到第</div>';
        str += '                                                    </td>';
        str += '                                                    <td width="25" height="22" valign="middle">';
        str += '                                                        <input name="textfield" type="text" style="height: 12px; width: 25px;" size="5" />';
        str += '                                                    </td>';
        str += '                                                    <td width="23" height="22" valign="middle">页</td>';
        str += '                                                    <td width="30" height="22" valign="middle">';
        str += '                                                        <img src="../../img/go.gif" width="37" height="15" />';
        str += '                                                    </td>';
        str += '                                                </tr>';
        str += '                                             </table>';
    }
    str += '                                        </div>';
    str += '                                    </td>';
    str += '                                </tr>';
    str += '                            </table>';
    str += '                        </td>';
    str += '                        <td width="14">';
    str += '                            <img src="../../img/tab_22.gif" width="14" height="29" />';
    str += '                        </td>';
    str += '                    </tr>';
    str += '                </table>';
    str += '            </td>';
    str += '        </tr>';
    str += '    </table>';
    $("RolesList").innerHTML = str;
}